import 'package:get/get.dart';
import 'package:pull_to_refresh/pull_to_refresh.dart';
import 'package:smart_devices/model/inventory.dart';

class InventoryTaskLogic extends GetxController with ScrollMixin {
  RxString search = RxString('');

  RxInt tabIndex = RxInt(0);

  RefreshController refreshController = RefreshController();

  RxList<InventoryTaskModel> pageList = RxList([]);

  Future<void> onRefresh() async {
    /// 发起请求
    await Future.delayed(const Duration(milliseconds: 2000));
    refreshController.refreshCompleted(resetFooterState: true);
  }

  Future<void> onLoading() async {
    /// 发起请求
    await Future.delayed(const Duration(milliseconds: 2000));

    /// if failed, use loadFailed(), if no data return, use LoadNodata()
    if (pageList.length > 15) {
      return refreshController.loadNoData();
    }

    /// 添加
    pageList.add(InventoryTaskModel(
        imgUrl:
            'https://img0.baidu.com/it/u=2020518972,2077284106&fm=253&fmt=auto&app=120&f=JPEG?w=889&h=500',
        name: '电梯设备',
        code: 'SB0792789',
        location: '生产车间二层'));

    /// 加载完毕
    refreshController.loadComplete();
  }

  @override
  void onInit() {
    for (var i = 0; i < 10; i++) {
      pageList.add(InventoryTaskModel(
          imgUrl:
              'https://img0.baidu.com/it/u=2020518972,2077284106&fm=253&fmt=auto&app=120&f=JPEG?w=889&h=500',
          name: '电梯设备',
          code: 'SB0792789',
          location: '生产车间二层'));
    }
    super.onInit();
  }

  @override
  void onClose() {
    refreshController.dispose();
    super.onClose();
  }

  @override
  Future<void> onEndScroll() {
    return Future.value();
  }

  @override
  Future<void> onTopScroll() {
    return Future.value();
  }
}
